package org.road0329.tools.proto_parse_tool.chargingpile;

import org.road0329.tools.proto_parse_tool.utils.ProtocolUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 设备地址
 *
 * @author road
 */
public class ChargingPile extends MsgCommData {
    private static Logger logger = LoggerFactory.getLogger(ChargingPile.class);

    private Integer pileId;

    private Integer eid;

    /**
     * 充电桩编码，8字节，以报文顺序存放
     */
    private String code;

    /**
     * 充电接口标识
     */
    private int gunNo;

    public Integer getPileId() {
        return pileId;
    }

    public void setPileId(Integer pileId) {
        this.pileId = pileId;
    }

    public Integer getEid() {
        return eid;
    }

    public void setEid(Integer eid) {
        this.eid = eid;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public void setGunNo(int gunNo) {
        this.gunNo = gunNo;
    }

    public String getCode() {
        return code;
    }

    public int getGunNo() {
        return gunNo;
    }

    /**
     * 以字符串形式设置充电桩编码
     */
    public byte[] packCode() {
        String commAddr = ProtocolUtils.reverse(code, code.length());
        return ProtocolUtils.StringToHex(commAddr, 8);
    }

    /**
     * 以阅读顺序显示设备地址
     *
     * @return
     */
    public String parseCode(byte[] value) {
        if(value == null || value.length != 8) {
            logger.warn("桩编码为空 或 长度不是8字节");
            return "";
        }
        code = ProtocolUtils.getStringByBCD(value,0, 8);
        return code;
    }

    public int parseGunNo(byte value) {
        gunNo = value;
        return value;
    }

    public byte packGunNo() {
        return (byte)(gunNo & 0xff);
    }
}
